package com.example.jsonhelper.framework

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import com.example.jsonhelper.R

/**
 *
 * @author Yingyong Lao
 * 创建时间 2022/8/17 22:30
 * @version 1.0
 */
open class LyyBaseActivity:AppCompatActivity() {

    companion object{
        private const val TAG = "LyyBaseActivity"
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.lyy_base_act)
        Log.d(TAG, "onCreate: ${this.javaClass.name}")
        LyyActivityCollector.addAct(this)
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "onDestroy: ${this.javaClass.name}")
        LyyActivityCollector.removeAct(this)
    }

    protected fun initTitleBar(title:String="标题",subTitle:String="",isShowBackIcon:Boolean=true){
        val toolbar = findViewById<Toolbar>(R.id.toolbar)
        if (toolbar==null){
            Log.e(TAG, "活动${this.javaClass.name}布局文件没有引入toolbar")
        }
        toolbar?.setTitle(title)
        toolbar?.subtitle=subTitle
        setSupportActionBar(toolbar)
        if (isShowBackIcon){
            toolbar?.setNavigationIcon(R.drawable.ic_chevron_left_black_24dp)
            toolbar?.setNavigationOnClickListener {
                finish()
            }
        }

    }
}